Skip to content

refactor: Add initial wrapper classes for all SLEs - #7886

Open
mvadari wants to merge 8 commits into
developfrom
mvadari/rearch/init
Open

refactor: Add initial wrapper classes for all SLEs#7886
mvadari wants to merge 8 commits into
developfrom
mvadari/rearch/init

Conversation

@mvadari

@mvadari mvadari commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Title pretty much says it all - this PR adds some wrapper classes for all ledger entry types, intended to replace the use of raw SLEs.

Context of Change

A production-grade Step 1 version of #7791

API Impact

N/A

@mvadari
mvadari requested review from a1q123456, bthomee and ximinez July 28, 2026 15:52
@mvadari mvadari changed the title refactor: Add wrapper classes for all SLEs refactor: Add initial wrapper classes for all SLEs Jul 28, 2026
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new SLEBase<ViewT> template and a set of thin, per-ledger-entry wrapper classes (e.g., AccountRootEntry<ViewT>, OfferEntry<ViewT>) intended as the first step toward replacing direct use of raw STLedgerEntry/SLE across the codebase.

Changes:

  • Added include/xrpl/ledger/helpers/SLEBase.h, providing a view-parameterized wrapper with compile-time gated writable operations.
  • Added initial wrapper headers for a broad set of ledger entry (SLE) types, each providing a convenience constructor that resolves the entry from a Keylet/keylet helper against a view.
  • Established ReadOnlySLE and WritableSLE aliases as generic wrappers for unknown concrete ledger entry types.

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 32 comments.

Show a summary per file
File Description
include/xrpl/ledger/helpers/SLEBase.h Introduces the core view-parameterized base wrapper for SLE access/mutation.
include/xrpl/ledger/helpers/AccountRootEntry.h Adds an AccountRoot SLE wrapper with a keylet::account constructor.
include/xrpl/ledger/helpers/AMMEntry.h Adds an AMM SLE wrapper with a keylet::amm constructor.
include/xrpl/ledger/helpers/AmendmentsEntry.h Adds an Amendments SLE wrapper with a keylet::amendments constructor.
include/xrpl/ledger/helpers/BridgeEntry.h Adds a Bridge SLE wrapper with a keylet::bridge constructor.
include/xrpl/ledger/helpers/CheckEntry.h Adds a Check SLE wrapper with a keylet::check constructor.
include/xrpl/ledger/helpers/CredentialEntry.h Adds a Credential SLE wrapper with a keylet::credential constructor.
include/xrpl/ledger/helpers/DelegateEntry.h Adds a Delegate SLE wrapper with a keylet::delegate constructor.
include/xrpl/ledger/helpers/DepositPreauthEntry.h Adds a DepositPreauth SLE wrapper with a keylet::depositPreauth constructor.
include/xrpl/ledger/helpers/DIDEntry.h Adds a DID SLE wrapper with a keylet::did constructor.
include/xrpl/ledger/helpers/DirectoryNodeEntry.h Adds a DirectoryNode SLE wrapper with a keylet::ownerDir constructor.
include/xrpl/ledger/helpers/EscrowEntry.h Adds an Escrow SLE wrapper with a keylet::escrow constructor.
include/xrpl/ledger/helpers/FeeSettingsEntry.h Adds a FeeSettings SLE wrapper with a keylet::feeSettings constructor.
include/xrpl/ledger/helpers/LedgerHashesEntry.h Adds a LedgerHashes/SkipList SLE wrapper with a keylet::skip constructor.
include/xrpl/ledger/helpers/LoanBrokerEntry.h Adds a LoanBroker SLE wrapper with a keylet::loanBroker constructor.
include/xrpl/ledger/helpers/LoanEntry.h Adds a Loan SLE wrapper with a keylet::loan constructor.
include/xrpl/ledger/helpers/MPTokenEntry.h Adds an MPToken SLE wrapper with a keylet::mptoken constructor.
include/xrpl/ledger/helpers/MPTokenIssuanceEntry.h Adds an MPTokenIssuance SLE wrapper with a keylet::mptokenIssuance constructor.
include/xrpl/ledger/helpers/NegativeUNLEntry.h Adds a NegativeUNL SLE wrapper with a keylet::negativeUNL constructor.
include/xrpl/ledger/helpers/NFTokenOfferEntry.h Adds an NFTokenOffer SLE wrapper with a keylet::nftokenOffer constructor.
include/xrpl/ledger/helpers/NFTokenPageEntry.h Adds an NFTokenPage SLE wrapper with a keylet::nftokenPage constructor.
include/xrpl/ledger/helpers/OfferEntry.h Adds an Offer SLE wrapper with a keylet::offer constructor.
include/xrpl/ledger/helpers/OracleEntry.h Adds an Oracle SLE wrapper with a keylet::oracle constructor.
include/xrpl/ledger/helpers/PayChannelEntry.h Adds a PayChannel SLE wrapper with a keylet::payChannel constructor.
include/xrpl/ledger/helpers/PermissionedDomainEntry.h Adds a PermissionedDomain SLE wrapper with a keylet::permissionedDomain constructor.
include/xrpl/ledger/helpers/RippleStateEntry.h Adds a RippleState SLE wrapper with a keylet::trustLine constructor.
include/xrpl/ledger/helpers/SignerListEntry.h Adds a SignerList SLE wrapper with a keylet::signerList constructor.
include/xrpl/ledger/helpers/SponsorshipEntry.h Adds a Sponsorship SLE wrapper with a keylet::sponsorship constructor.
include/xrpl/ledger/helpers/TicketEntry.h Adds a Ticket SLE wrapper with a keylet::ticket constructor.
include/xrpl/ledger/helpers/VaultEntry.h Adds a Vault SLE wrapper with a keylet::vault constructor.
include/xrpl/ledger/helpers/XChainOwnedClaimIDEntry.h Adds an XChainOwnedClaimID SLE wrapper with a keylet::xChainClaimID constructor.
include/xrpl/ledger/helpers/XChainOwnedCreateAccountClaimIDEntry.h Adds an XChainOwnedCreateAccountClaimID SLE wrapper with a keylet::xChainCreateAccountClaimID constructor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread include/xrpl/ledger/helpers/SLEBase.h
Comment thread include/xrpl/ledger/helpers/AccountRootEntry.h
Comment thread include/xrpl/ledger/helpers/AMMEntry.h
Comment thread include/xrpl/ledger/helpers/AmendmentsEntry.h
Comment thread include/xrpl/ledger/helpers/BridgeEntry.h
Comment thread include/xrpl/ledger/helpers/SponsorshipEntry.h
Comment thread include/xrpl/ledger/helpers/TicketEntry.h
Comment thread include/xrpl/ledger/helpers/VaultEntry.h
Comment thread include/xrpl/ledger/helpers/XChainOwnedClaimIDEntry.h
Comment thread include/xrpl/ledger/helpers/XChainOwnedCreateAccountClaimIDEntry.h

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type-mismatch and null-pointer issues in SLE wrapper constructors — flagged inline.

Comment thread include/xrpl/ledger/helpers/SLEBase.h
Comment thread include/xrpl/ledger/helpers/SLEBase.h Outdated

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Const-correctness violation (line 39), stale state after erase (line 231), and null-dereference in release builds (line 128) — see inline.

{
// Views are never const objects; the read-only wrapper only holds a const
// reference because it does not itself modify the view.
if (auto const applyView = dynamic_cast<ApplyView*>(const_cast<ReadView*>(&view)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const_cast mutates const ReadView through peek(). Require explicit non-const ref for peek-based resolution:

inline SLE::const_pointer
resolveEntry(ReadView const& view, Keylet const& key)
{
    return view.read(key);
}

requires kIsWritable
{
XRPL_ASSERT(canModify(), "xrpl::SLEBase::erase : can modify");
view_.erase(sle_);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erase() doesn't reset sle_ to nullptr; subsequent calls operate on stale entry. Reset to null:

void
erase()
    requires kIsWritable
{
    XRPL_ASSERT(canModify(), "xrpl::SLEBase::erase : can modify");
    view_.erase(sle_);
    sle_ = nullptr;
}

else
{
XRPL_ASSERT(exists(), "xrpl::SLEBase::keylet : exists");
return Keylet(sle_->getType(), sle_->key());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keylet() relies on debug-only assertions; crashes in release builds. Use runtime check when !exists():

[[nodiscard]] Keylet
keylet() const
{
    if constexpr (kIsWritable)
    {
        return key_;
    }
    else
    {
        if (!exists())
            throw std::logic_error("keylet(): entry does not exist");
        return Keylet(sle_->getType(), sle_->key());
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants